﻿using CheatMenu.Managers;
using System;
using System.Collections.Generic;
using System.Linq;

namespace CheatMenu.Utils
{
    public class CommandGroup : Group<Command>
    {
        //public string Name { get; set; }
        //public List<Command> Commands { get; private set; } = new List<Command>();

        public CommandGroup(string name) : base(name) { }

        public void Add(string name, Action<Command> action, bool toggleState = false)
        {
            if (Children.Where((c) => c.Name.Equals(name, StringComparison.OrdinalIgnoreCase)).Count() == 0)
                Children.Add(new Command(name, action, toggleState));
            else
                LogManager.LogWarning($"Trying to add existing command with name: {name}");
        }

        public void Remove(string name)
        {
            var existingCommand = Children.Where((c) => c.Name.Equals(name, StringComparison.OrdinalIgnoreCase));
            if (existingCommand.Count() == 1)
                Children.Remove(existingCommand.First());
            else
                LogManager.LogWarning($"Trying to remove non-existing command with name: {name}");
        }
    }
}
